package com.example.child_protection.controller;

import com.example.child_protection.dto.base.BaseResponseDTO;
import com.example.child_protection.dto.request.SimpleIdRequestDTO;
import com.example.child_protection.dto.request.add.CategoryInsertRequestDTO;
import com.example.child_protection.dto.request.find.CategoryRequestDTO;
import com.example.child_protection.dto.request.update.CategoryUpdateRequestDTO;
import com.example.child_protection.dto.response.CategoryListResponseDTO;
import com.example.child_protection.dto.response.CategoryResponseDTO;
import com.example.child_protection.service.CategoryManageService;
import com.example.child_protection.service.CategoryQueryService;
import com.example.child_protection.util.ContentType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 类目管理控制层
 * @date 2018-11-2
 * @author Biz
 */
@RestController
@RequestMapping("category")
@Api(value = "/api-category", description = "类目管理")
public class CategoryController extends BaseController {

    @Autowired
    public CategoryManageService categoryManageService;

    @Autowired
    public CategoryQueryService categoryQueryService;

    @ApiOperation(value ="查询类目", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/findId", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public CategoryResponseDTO findId(SimpleIdRequestDTO requestDTO,HttpServletRequest request)throws Exception{
        CategoryResponseDTO responseDTO = categoryQueryService.findId(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="查询类目列表信息", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/findList", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public CategoryListResponseDTO findList(CategoryRequestDTO requestDTO, HttpServletRequest request)throws Exception{
        CategoryListResponseDTO responseDTO = categoryQueryService.findList(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="添加类目", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/insert", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public BaseResponseDTO insert(CategoryInsertRequestDTO requestDTO)throws Exception{
        requestDTO.setCreatePersonId(this.getLoginUserId());
        requestDTO.setLastUpdatePersonId(this.getLoginUserId());
        BaseResponseDTO responseDTO = categoryManageService.insert(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="修改类目", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/update", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public BaseResponseDTO update(CategoryUpdateRequestDTO requestDTO)throws Exception{
        requestDTO.setLastUpdatePersonId(this.getLoginUserId());
        BaseResponseDTO responseDTO = categoryManageService.update(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="删除类目", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/delete", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public BaseResponseDTO delete(SimpleIdRequestDTO requestDTO)throws Exception{
        requestDTO.setLastUpdatePersonId(this.getLoginUserId());
        BaseResponseDTO responseDTO = categoryManageService.delete(requestDTO);
        return responseDTO;
    }

}
